package com.moleq.logic;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;

import com.moleq.models.DeptSalesRpt;
import com.moleq.models.FixedTotalRpt;
import com.moleq.models.FreeFuncRpt;
import com.moleq.models.GroupSalesRpt;
import com.moleq.models.MultiTareSalesRpt;
import com.moleq.models.PluSalesRpt;
import com.moleq.network.Constant;
import com.moleq.service.DeptSalesRptService;
import com.moleq.service.FixedTotalRptService;
import com.moleq.service.FreeFuncRptService;
import com.moleq.service.GroupSalesRptService;
import com.moleq.service.MultiTareSalesRptService;
import com.moleq.service.PluSalesRptService;
import com.moleq.service.ServiceManager;
import com.moleq.util.MoleQUtil;

public class ReportManager {
	private static final int Amt = 12;
	private static final int Name = 28;
	private static final int Qty = 5;
	private Context context;
	private List<DeptSalesRpt> DepListRpt = null;
	private DeptSalesRptService DepService = null;
	private List<FixedTotalRpt> FixTotalListRpt = null;
	private FixedTotalRptService FixTotalService = null;
	private List<FreeFuncRpt> FreeFuncListRpt = null;
	private FreeFuncRptService FreeFuncService = null;
	private List<GroupSalesRpt> GroupSalesListRpt = null;
	private GroupSalesRptService GroupSalesService = null;
	private List<MultiTareSalesRpt> MultiTareSalesListRpt = null;
	private MultiTareSalesRptService MultiTareSalesService = null;
	private List<PluSalesRpt> PLUListRpt = null;

	private PluSalesRptService PLUservice = null;

	
	public  HashMap<String, Report> respots = new HashMap<String, Report>();
	
	public static final int TYPE_COLLECTION = 0 ;//"com.moleq.report.type.collection";
	public static final int TYPE_CONSOLIDATION = 1;//"com.moleq.report.type.consolidation";

	private int  reportType = TYPE_COLLECTION;
	
	public ReportManager() {
		
//		respots.put(Constant.RPT_FIXED_TOTAL, new Report());
//		respots.put(Constant.RPT_DEPARTMENT, new Report());
//		respots.put(Constant.RPT_FUNCTION, new Report());
//		respots.put(Constant.RPT_SCANNING_ITEM, new Report());
//		respots.put(Constant.RPT_GROUP, new Report());
//		respots.put(Constant.RPT_PLU_MULTI_TARE, new Report());
		
	}
	
	public int getReportType() {
		return reportType;
	}

	public void setReportType(int reportType) {
		this.reportType = reportType;
	}
	
	public String export(String startDate,String endDate){
		
		return "";
	}
	
	public String getReportContent(String reportName){
		String result = "";
		
		if (respots != null) {
			result = respots.get(reportName).toPrintReport();
		}
		
		return result;
	}

	public ReportManager(Context context) {
		this.context = context;
	}

	public String CreateDepartmentReport(String Date) {
		DepService = new DeptSalesRptService(context);
		DepListRpt = DepService.getDeptSalesRptsByDate(Date);
		if (DepListRpt.size() <= 0)
			return "";
		String result = "\n";
		result += SetTitle("Department", Date) + "\n";
		int SumQty = 0;
		double SumAmt = 0;
		for (int i = 0; i < DepListRpt.size(); i++) {
			String sDepName = DepService.getDeptName(String.valueOf(DepListRpt.get(i).getDs_dept()));
			if (sDepName.trim().equals("") || sDepName == null) {
				sDepName = String.valueOf((int) DepListRpt.get(i).getDs_dept());
			}
			int iDepQty = DepListRpt.get(i).getDs_qty();
			if (iDepQty > 0) {
				SumQty += DepListRpt.get(i).getDs_qty();
				double dDepAmt = DepListRpt.get(i).getDs_amt();
				SumAmt += DepListRpt.get(i).getDs_amt();
				result += "\n ";
				result += SetSpaceE(Name, sDepName);
				result += SetSpaceB(Qty, String.valueOf(iDepQty));
				result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(dDepAmt));
				result += " ";
			}
		}
		result += "\n";
		result += "-----------------------------------------------";
		result += "\n ";
		result += SetSpaceE(Name, "Total");
		result += SetSpaceB(Qty, String.valueOf(SumQty));
		result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(SumAmt));
		result += " \n\n";
		return result;
	}

	public String CreateFixedTotalReport(String Date) {
//		FixTotalService = new FixedTotalRptService(context);
		FixTotalService = ServiceManager.getInstance().mFixedTotalRptService;
		FixTotalListRpt = FixTotalService.getFixedTotalRepByDate(Date);
		String result = MakeFixedTotalReport(Date);
		return result;
	}

	public String CreateFixedTotalReport(String Date, String UserId) {
//		FixTotalService = new FixedTotalRptService(context);
		FixTotalService = ServiceManager.getInstance().mFixedTotalRptService;
		FixTotalListRpt = FixTotalService.getFixedTotalRepByDate(Date, UserId);
		String result = MakeFixedTotalReport(Date);
		return result;
	}

	public String CreateFreeFunctionReport(String Date) {
//		FreeFuncService = new FreeFuncRptService(context);
		FreeFuncService = ServiceManager.getInstance().mFreeFuncRptService;
		FreeFuncListRpt = FreeFuncService.getFreeFuncRptByDate(Date);
		String result = MakeFreeFunctionReport(Date);
		return result;
	}

	public String CreateFreeFunctionReport(String Date, String UserId) {
//		FreeFuncService = new FreeFuncRptService(context);
		FreeFuncService = ServiceManager.getInstance().mFreeFuncRptService;
		FreeFuncListRpt = FreeFuncService.getFreeFuncRptByDate(Date, UserId);
		String result = MakeFreeFunctionReport(Date);
		return result;
	}

	public String CreateGroupSalesReport(String Date) {
		GroupSalesService = new GroupSalesRptService(context);
		GroupSalesListRpt = GroupSalesService.getGroupSalesRptByDate(Date);
		if (GroupSalesListRpt.size() <= 0)
			return "";
		String result = "\n";
		result += SetTitle("Group", Date) + "\n";
		int SumQty = 0;
		double SumAmt = 0;
		for (int i = 0; i < GroupSalesListRpt.size(); i++) {
			String sGrpName = GroupSalesService.getDeptGroupName(String.valueOf(GroupSalesListRpt.get(i).getGs_group()));
			int iGrpQty = GroupSalesListRpt.get(i).getGs_qty();
			if (iGrpQty > 0) {
				SumQty += GroupSalesListRpt.get(i).getGs_qty();
				double dGrpAmt = GroupSalesListRpt.get(i).getGs_amt();
				SumAmt += GroupSalesListRpt.get(i).getGs_amt();
				result += "\n ";
				result += SetSpaceE(Name, sGrpName);
				result += SetSpaceB(Qty, String.valueOf(iGrpQty));
				result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(dGrpAmt));
				result += " ";
			}
		}
		result += "\n";
		result += "-----------------------------------------------";
		result += "\n ";
		result += SetSpaceE(Name, "Total");
		result += SetSpaceB(Qty, String.valueOf(SumQty));
		result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(SumAmt));
		result += " \n\n";
		return result;
	}

	public String CreateMultiTareSalesReport(String Date) {
		MultiTareSalesService = new MultiTareSalesRptService(context);
		MultiTareSalesListRpt = MultiTareSalesService.getMultiTareSalesRptsByDate(Date);
		if (MultiTareSalesListRpt.size() <= 0)
			return "";
		String result = "\n";
		result += SetTitle("Multi. Tare", Date) + "\n";
		int SumQty = 0;
		double SumAmt = 0;
		String upcString = "";
		for (int i = 0; i < MultiTareSalesListRpt.size(); i++) {
			String sTareName = MultiTareSalesService.getTareName(String.valueOf(MultiTareSalesListRpt.get(i).getMt_tare_no()));
			int iTareQty = MultiTareSalesListRpt.get(i).getMt_qty();
			if (iTareQty > 0) {
				result += "\n ";
				if (!upcString.equals(MultiTareSalesListRpt.get(i).getMt_upc_plu())) {
					upcString = MultiTareSalesListRpt.get(i).getMt_upc_plu();
					if (upcString.length() > 45) {
						upcString = upcString.substring(0, 45);
					}
					result += upcString + "\n ";
				}
				result += SetSpaceE(Name, "  " + sTareName);
				result += SetSpaceB(Qty, "");
				result += SetSpaceB(Amt, String.valueOf(iTareQty));
				result += " ";
			}
		}
		result += "\n";
		result += "-----------------------------------------------";
		result += " \n\n";
		return result;
	}

	public String CreateScanningItemReport(String Date) {
		PLUservice = new PluSalesRptService(context);
		PLUListRpt = PLUservice.getPLUSalesRptByDate(Date);
		if (PLUListRpt.size() <= 0)
			return "";
		String result = "\n";
		result += SetTitle("Scanning Item", Date) + "\n";
		int SumQty = 0;
		double SumAmt = 0;
		for (int i = 0; i < PLUListRpt.size(); i++) {
			String sPLU = PLUListRpt.get(i).getUs_upc_plu();
			String itemName = "";
			if (sPLU.length() < 12) {
				itemName = PLUservice.getItemDiscount(sPLU);
			} else {
				itemName = PLUservice.getItemName(sPLU);
			}
			double dWeight = PLUListRpt.get(i).getus_weight();
			int iDepQty = PLUListRpt.get(i).getus_qty();
			double dAmt = PLUListRpt.get(i).getus_amt();
			String sType = PLUListRpt.get(i).getUs_type();
			if (iDepQty > 0 || dWeight > 0 || dAmt > 0) {
				SumQty += PLUListRpt.get(i).getus_qty();
				SumAmt += PLUListRpt.get(i).getus_amt();
				if (sType.equals("1020")) {
					result += "\n ";
					result += SetSpaceE(Name, "    Discount");
					result += SetSpaceB(Qty, String.valueOf(iDepQty));
					result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(dAmt));
				} else {
					result += "\n ";
					result += SetSpaceE(Name, sPLU);
					result += SetSpaceB(Qty, String.valueOf(iDepQty));
					result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(dAmt));
					result += " \n ";
					result += SetSpaceE(Name, itemName);
					if (dWeight > 0) {
						result += SetSpaceB(Qty, String.valueOf(dWeight));
						result += " " + PLUListRpt.get(i).getus_wt_unit();
					}
				}
				
			}
		}
		result += "\n";
		result += "-----------------------------------------------";
		result += "\n ";
		result += SetSpaceE(Name, "Total");
		// result += SetSpaceB(PLUQty, String.valueOf(SumQty));
		result += SetSpaceB(Qty, " ");
		result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(SumAmt));
		result += " \n\n";
		return result;
	}

	public String MakeFixedTotalReport(String Date) {
		if (FixTotalListRpt.size() <= 0)
			return "";
		String result = "\n";
		result += SetTitle("Fixed Total", Date) + "\n";
		if (FixTotalListRpt.get(0).getFt_gs_amt() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Item/Sales");
			result += SetSpaceB(Qty, String.valueOf(FixTotalListRpt.get(0).getFt_gs_qty()));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_gs_amt()));
		}
		if (FixTotalListRpt.get(0).getFt_ns_amt() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Net Sales");
			result += SetSpaceB(Qty, String.valueOf(FixTotalListRpt.get(0).getFt_ns_qty()));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_ns_amt()));
		}
		if (FixTotalListRpt.get(0).getFt_cash_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Cash In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_cash_id()));
		}
		if (FixTotalListRpt.get(0).getFt_credit_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Credit In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_credit_id()));
		}
		if (FixTotalListRpt.get(0).getFt_debit_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Debit In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_debit_id()));
		}
		if (FixTotalListRpt.get(0).getFt_check_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Check In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_check_id()));
		}
		if (FixTotalListRpt.get(0).getFt_foodstamp_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "FoodStamp In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_foodstamp_id()));
		}
		if (FixTotalListRpt.get(0).getFt_ebt_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "EBT In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_ebt_id()));
		}
		if (FixTotalListRpt.get(0).getFt_gc_id() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Gift Card In Drawer");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_gc_id()));
		}
		if (FixTotalListRpt.get(0).getFt_refund_amt() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Refund Sales");
			result += SetSpaceB(Qty, String.valueOf(FixTotalListRpt.get(0).getFt_refund_qty()));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_refund_amt()));
		}
		if (FixTotalListRpt.get(0).getFt_trn_count() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Transaction Count");
			result += SetSpaceB(Qty, String.valueOf(FixTotalListRpt.get(0).getFt_trn_count()));
			result += SetSpaceB(Amt, "");
		}
		if (FixTotalListRpt.get(0).getFt_average() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Average");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_average()));
		}
		if (FixTotalListRpt.get(0).getFt_discount() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Discount");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_discount()));
		}
		if (FixTotalListRpt.get(0).getFt_coupon() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Coupon");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_coupon()));
		}
		if (FixTotalListRpt.get(0).getFt_rounding() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Rounding");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_rounding() * (-1)));
		}
		if (FixTotalListRpt.get(0).getFt_vdr_coupon() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Vendor Coupon");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_vdr_coupon()));
		}
		if (FixTotalListRpt.get(0).getFt_taxable_1() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Taxable 1");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_taxable_1()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_1() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax 1");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_1()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_exem_1() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax Exempt 1");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_exem_1()));
		}
		if (FixTotalListRpt.get(0).getFt_taxable_2() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Taxable 2");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_taxable_2()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_2() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax 2");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_2()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_exem_2() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax Exempt 2");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_exem_2()));
		}
		if (FixTotalListRpt.get(0).getFt_taxable_3() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Taxable 3");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_taxable_3()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_3() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax 3");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_3()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_exem_3() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax Exempt 3");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_exem_3()));
		}
		if (FixTotalListRpt.get(0).getFt_taxable_4() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Taxable 4");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_taxable_4()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_4() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax 4");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_4()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_exem_4() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax Exempt 4");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_exem_4()));
		}
		if (FixTotalListRpt.get(0).getFt_taxable_5() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Taxable 5");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_taxable_5()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_5() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax 5");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_5()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_exem_5() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax Exempt 5");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_exem_5()));
		}
		if (FixTotalListRpt.get(0).getFt_taxable_6() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Taxable 6");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_taxable_6()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_6() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax 6");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_6()));
		}
		if (FixTotalListRpt.get(0).getFt_tax_exem_6() != 0) {
			result += "\n ";
			result += SetSpaceE(Name, "Tax Exempt 6");
			result += SetSpaceB(Qty, String.valueOf(""));
			result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(FixTotalListRpt.get(0).getFt_tax_exem_6()));
		}
		result += "\n";
		result += "-----------------------------------------------";
		result += " \n\n";
		return result;
	}

	public String MakeFreeFunctionReport(String Date) {
		if (FreeFuncListRpt.size() <= 0)
			return "";
		String result = "\n";
		result += SetTitle("Free Function", Date) + "\n";
		for (int i = 0; i < FreeFuncListRpt.size(); i++) {
			String sFunName = FreeFuncService.getFunName(String.valueOf(FreeFuncListRpt.get(i).getFf_func_id()));
			int iFunQty = FreeFuncListRpt.get(i).getFf_qty();
			double dFunAmt = FreeFuncListRpt.get(i).getFf_amt();
			if (iFunQty > 0) {
				result += "\n ";
				result += SetSpaceE(Name, sFunName);
				result += SetSpaceB(Qty, String.valueOf(iFunQty));
				if (dFunAmt == 0) {
					result += SetSpaceB(Amt, "");
				} else {
					result += SetSpaceB(Amt, MoleQUtil.fixPrintPrice(dFunAmt));
				}
				result += " ";
			}
		}
		result += "\n";
		result += "-----------------------------------------------";
		result += " \n\n";
		return result;
	}

	public String SetSpaceB(int MaxSize, String Context) {
		String result = "";
		int space = MaxSize - Context.length();
		if (space > 0) {
			for (int j = 0; j < space; j++) {
				result += " ";
			}
			result += Context;
		} else {
			result = Context.substring(0, MaxSize);
		}
		return result;
	}

	public String SetSpaceE(int MaxSize, String Context) {
		String result = "";
		int space = MaxSize - Context.length();
		if (space > 0) {
			result = Context;
			for (int j = 0; j < space; j++) {
				result += " ";
			}
		} else {
			result = Context.substring(0, MaxSize);
		}
		return result;
	}

	public String SetTitle(String RepName, String Date) {
		int length = 47;
		String result = "";
		String sDate = MoleQUtil.fixDateTime2(Date, "yyyy-MM-dd", "yyyyMMdd");
		int SpaceSize = length - (RepName.length() + sDate.length() + 2);
		result = " " + RepName;
		for (int i = 0; i < SpaceSize; i++) {
			result += " ";
		}
		result += sDate;
		return result;
	}

	
}
